﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【磁头】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto磁头
    /// </summary>
    public abstract class AutoMagnetHeadMapping : BaseMapping<MagnetHead, MagnetHeadModel, MagnetHeadFilterModel>
    {
        public AutoMagnetHeadMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override MagnetHeadModel Entity2Model(MagnetHead entity)
        {
            MagnetHeadModel model = new MagnetHeadModel();

            model.MHID = entity.MHID;
            model.GroupInfoID = entity.GroupInfoID;
            model.DeviceID = entity.DeviceID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override MagnetHead Model2Entity(MagnetHeadModel model)
        {
            MagnetHead entity = new MagnetHead();

            entity.MHID = model.MHID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.DeviceID = model.DeviceID;
            
            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<MagnetHead> FilterModel2Where(MagnetHeadFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._MHID.HasValue)
            {
                where = where.And(x => x.MHID == filterModel._MHID.Value);
            }
            if (filterModel._MHIDs.IsNotEmpty() && filterModel._MHIDs.Count > 0)
            {
                where = where.And(x => filterModel._MHIDs.Contains(x.MHID));
            }
            if (filterModel._NotMHIDs.IsNotEmpty() && filterModel._NotMHIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotMHIDs.Contains(x.MHID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //设备
            if (filterModel._DeviceID.HasValue)
            {
                where = where.And(x => x.DeviceID == filterModel._DeviceID);
            }
            if (filterModel._DeviceIDs.IsNotEmpty() && filterModel._DeviceIDs.Count > 0)
            {
                where = where.And(x => filterModel._DeviceIDs.Contains(x.DeviceID));
            }
            if (filterModel._NotDeviceIDs.IsNotEmpty() && filterModel._NotDeviceIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotDeviceIDs.Contains(x.DeviceID));
            }

            return where;
        }
        #endregion
    }
}

